'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:TaskChoosepeopleCtrl
 * @description
 * # TaskChoosepeopleCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('TaskChoosepeopleCtrl', function(openApi, DataService, $location, $routeParams) {
        this.peopleId = -1
        this.selectpeopleIndex = 0
        this.initData = function() {
            var param = {};
            param.departmentId = $routeParams.depId
            DataService.getData(openApi.getusersBydepId).then(function(data) {
                this.peoplelist = data
            }.bind(this))
        }
        this.initData();
        this.confirm = function() {
            if ($routeParams.from == "daily") {
                if (this.peopleId == -1) {
                    $location.path("task/dailylist/dep/" + this.peopleId)
                } else {
                    $location.path("task/dailylist/people/" + this.peopleId)
                }

            }
            if ($routeParams.from == "weekly") {
                if (this.peopleId == -1) {
                    $location.path("task/weeklylist/dep/" + this.peopleId)
                } else {
                    $location.path("task/weeklylist/people/" + this.peopleId)
                }

            }
        }
        this.selectpeople = function(item, index) {
            if (this.selectpeopleIndex == index) {
                return;
            }
            this.selectpeopleIndex = index;
            this.peopleId = item.value
        }
    });
